import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/new_guide_certification";

export const types_api = (showError = true) => {
  return Http.get<{
    guider_rank: any[];
    language: any[];
    identity_type2: any[];
    example_card_pic: string;
  }>(`/v3${baseUrl}/types`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const add_api = (data: any, showError = true) => {
  return Http.post(`/v3${baseUrl}/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const get_h5_status_api = (showError = true) => {
  return Http.get<{ certification_types: any[] }>(
    `/v3${baseUrl}/get_h5_status`
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const info_api = (data: { type: number }, showError = true) => {
  return Http.get<any>(`/v3${baseUrl}/info`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
